Wednesday, September 29, 2004

How to Integrate a Derivative


In the previous post, I had tried to use derivatives to improve the estimate for a single sample, but that turned out not to work very well. That was an approximation. To use the derivative exactly, the definition is f(x) - f(0) = int_0^x f`(y) dy.


Does this have a practical application? After all, if we do this on the example in the previous post, we go from a single integral to a double integral - it looks like we're making the problem harder! Ah, but this is Monte Carlo. The convergence rate is independent of dimensionality. So adding more integrals doesn't necessarily make the problem harder.


The final error does, however, depend on the intrinsic variance of the integral. In this example, this variance gets much worse, so making this transformation is not a good idea. In general, derivatives will vary more than the original function, so this technique is not likely useful in general. Unless the transformed problem has some other desirable features, like better importance sampling or something.


Finally, I should note that something similar to this is used in thermodynamic integration to get free energies.

Monday, September 27, 2004

Sometimes it doesn't work



The other day I had an idea about trying to improve MC samples. The Monte Carlo method for evaluating an integral is the average of a set of samples. Each sample can be considered a very crude approximation to the integral - each sample approximates the integrand as a constant. What if we could make each sample a better approximation, say by using a the derivative information at the sample point?


Another consideration is that the intrinsic variance of the integral (int [f(x)-ave(f)]^2) controls the accuracy of the MC approximation. If we could smooth the integrand, and lower the variance, the MC integral would be better. Perhaps expanding the integral in a series around the sample point and integrating would help smooth it?


Then reality struck. I tried it on v(x)*exp(-v(x)/T), with v(x) = 1/x^12. I made the expansion and integrated in an interval from [x-h,x+h], and graphed the result - it was clearly *not* smoother than the original function. It was also clear that the expansion was an approximation, and only correct in the limit of small h.


Upon further reflection, I realized a few things. One is that each MC sample may be a crude approximation to the integral, but it has the important property of being unbiased (ie, all the errors will average to zero). Any improvement in the sample value needs to retain this property.


Secondly, smoothing would be most valuable when the integrand is rapidly changing. And this is just the condition where the Taylor expansion is likely to be the least accurate. I suppose that any local smoothing of the integrand will suffer from this sort of problem.


Sometimes, it doesn't work. Ah, but that's what research is all about.

Saturday, September 04, 2004

Visualizing Wavefunctions



I've started learning VTK, Python, and Tk in order to look into visualizing wavefunctions. So far, I've made an application that plots a function of x and y. The user can change the plotted function in an edit box. Get the 2D plotter here.


I've also got a prototype application that plots a function of 3 variables, and lets the user choose a slice (a plane) through the displayed volume, and the application plots the 2D slice in a view that looks very much like the 2D plotter. But it's not quite ready for public consumption yet.